package com.guguskins.back.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guguskins.back.entity.GuContactDetails;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuContactDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-06-22
 */
@RestController
@RequestMapping("/contactDetails")
public class GuContactDetailsController {

    @Autowired
    private GuContactDetailsService contactDetailsService;

    @GetMapping("/list")
    public ResultVo getList() {
        List<GuContactDetails> contactDetailsList = contactDetailsService.list(new LambdaQueryWrapper<GuContactDetails>() {
            {
                select(GuContactDetails::getCdId, GuContactDetails::getCdTitle, GuContactDetails::getCdAccount, GuContactDetails::getCdImageUrl, GuContactDetails::getCdQrCode);
                orderByAsc(GuContactDetails::getCdSort);
            }
        });
        return ResultVo.success(contactDetailsList);
    }

    @GetMapping("/back/list")
    public ResultVo getBackList() {
        return ResultVo.success(contactDetailsService.list(), "查找成功");
    }

    @PostMapping("/back/update")
    public ResultVo backUpdate(@RequestBody GuContactDetails contactDetails) {
        contactDetailsService.updateById(contactDetails);
        return ResultVo.success("修改成功");
    }

    @PostMapping("/back/insert")
    public ResultVo backInsert(@RequestBody GuContactDetails contactDetails) {
        contactDetailsService.save(contactDetails);
        return ResultVo.success("添加成功");
    }

    @GetMapping("/back/delect")
    public ResultVo backDelect(@RequestParam(value = "id", required = false) int id) {
        contactDetailsService.removeById(id);
        return ResultVo.success("删除成功");
    }
}
